﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ddcCajamarca.BusinessEntities.Documentos;
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;

namespace ddcCajamarca.Repository.Mapping.Documentos
{
    public class DetalleRegistroMap : EntityTypeConfiguration<DetalleRegistro>
    {
        public DetalleRegistroMap()
        {
            this.HasKey(c => c.ItemCorrelativo);

            this.Property(c => c.ItemCorrelativo)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(c => c.IdArea)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(c => c.IdRDocumento)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(c => c.Emisor)
                .HasMaxLength(50)
                .IsRequired();

            this.Property(c => c.Receptor)
                .HasMaxLength(50)
                .IsOptional();

            this.Property(c => c.Atiende)
                .HasMaxLength(50)
                .IsOptional();

            this.Property(c => c.FechDerivDocum)
                .HasColumnType("datetime2")
                .IsRequired();

            this.Property(c => c.FechRecepDocum)
                .HasColumnType("datetime2")
                .IsOptional();

            this.Property(c => c.FechAtenDocum)
                .HasColumnType("datetime2")
                .IsOptional();

            this.Property(c => c.Recibido)
                .IsOptional();

            this.Property(c => c.Observacion)
                .HasMaxLength(300)
                .IsOptional();

            this.Property(c => c.Movimientos)
                .IsOptional();

            this.Property(c => c.AreaDest)
                .HasMaxLength(50)
                .IsOptional();

            this.Property(c => c.Atendido)
                .IsOptional();

            this.Property(c => c.Observacion2)
                .HasMaxLength(300)
                .IsOptional();

            this.Property(c => c.Observacion3)
                .HasMaxLength(300)
                .IsOptional();

            this.ToTable("DetalleRegistro");
            this.Property(c => c.IdArea).HasColumnName("IdArea");
            this.Property(c => c.IdRDocumento).HasColumnName("IdRDocumento");
            this.Property(c => c.Emisor).HasColumnName("Emisor");
            this.Property(c => c.Receptor).HasColumnName("Receptor");
            this.Property(c => c.FechDerivDocum).HasColumnName("FechDerivDocum");
            this.Property(c => c.FechRecepDocum).HasColumnName("FechRecepDocum");
            this.Property(c => c.FechAtenDocum).HasColumnName("FechAtenDocum");
            this.Property(c => c.Recibido).HasColumnName("Recibido");
            this.Property(c => c.Observacion).HasColumnName("Observacion");
            this.Property(c => c.Movimientos).HasColumnName("Movimientos");
            this.Property(c => c.AreaDest).HasColumnName("AreaDest");
            this.Property(c => c.Observacion2).HasColumnName("Observacion2");
            this.Property(c => c.Observacion3).HasColumnName("Observacion3");
            this.Property(c => c.Atiende).HasColumnName("Atiende");

            this.HasRequired(c => c.Area)
                .WithMany(c => c.DetalleRegistros)
                .HasForeignKey(c => c.IdArea)
                .WillCascadeOnDelete(true);
            this.HasRequired(c => c.RDocumento)
                .WithMany(c => c.DetalleRegistros)
                .HasForeignKey(c => c.IdRDocumento)
                .WillCascadeOnDelete(true);
        }
    }
}
